import * as types from '../constants/ActionTypes';

const initialState = {
	active: false,
	secret: {}
};

export default function (state = initialState, action) {
	const {payload={}, error, meta = {}, type} = action;
	const {sequence = {}} = meta;
	if (sequence.type === 'start' || error) {
		return state;
	}

	const user = payload.user || {}
	const active = payload.active || false

	switch (type) {
		case types.CHECK_TOKEN:
		case types.SIGNIN:
		case types.SIGNUP:
			return {
                ...state,
                active: active,
                secret: user
			};
		case types.SIGNOUT:
			return initialState;
		default:
			return state;
	}
}
